package com.smile.frame.alibaba.services.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;

/**
 * 局部过滤器
 * @author LGC
 * @date 2021/12/9 11:44
 */
@Slf4j
@Component
public class LocalFilter extends AbstractGatewayFilterFactory<LocalFilter.NameConfig> implements Ordered {

    public LocalFilter() {
        super(NameConfig.class);
    }

    @Override
    public GatewayFilter apply(NameConfig config) {
        return (exchange, chain) -> {
            //获取请求对象
            ServerHttpRequest request = exchange.getRequest();

            log.info("局部过滤器....");

            return chain.filter(exchange);
        };
    }

    @Override
    public int getOrder() {
        return 3;
    }

    public static class NameConfig {
        private String name;

        public String getName() {
            return name;
        }
    }
}
